<template>
    <div class="tab-control">
        <div  @click="clickItem(key)" class="tab-control-item" v-for="(item,key) in titles" :key="key">
            <span :class="{isActive: key == currentIndex}" >{{item}}</span>
        </div>
    </div>
</template>

<script>
    export default {
        name:'TabControl',
        data () {
            return {
                currentIndex:0
            }
        },
        props:{
            titles:{
                type:Array,
                default(){
                    return []
                }
            },
        },
        methods:{
            clickItem(index){
                this.currentIndex = index
                this.$emit('tabClick',index)
            }
        }
    }
</script>

<style scoped>
    .tab-control{
        display: flex;
        height: 40px;
        line-height: 40px;
        text-align: center;
        font-size: 14px;
        background-color: #fff;
    }
    .tab-control-item{
        flex: 1;
    }
    .tab-control-item>span{
        padding: 5px;
    }
    .isActive{
        color: var(--color-high-text);
        border-bottom: 2px solid  var(--color-high-text)
    }
</style>